#ifndef _VECTOR_SPACE_H
#define _VECTOR_SPACE_H

#include <map>
#include <vector>
#include <tr1/memory>

namespace jsearch
{
	class page_db;
	struct item;
	struct raw_posting_list;
	struct disk_index_header;
	struct disk_index_data;

	typedef std::map< std::string, raw_posting_list > INDEX;
	typedef INDEX::value_type INDEX_V;

	const int  words_length_max = 4*10;

	class vector_space_indexer
	{
		public:
			vector_space_indexer( std::tr1::shared_ptr<page_db>& db,
					              std::string disk_db_name );

			bool build_index();
			bool persist();

			int size();
			bool empty();

			void print( std::ostream& os= std::cout );
		private:
			struct Impl;
			std::tr1::shared_ptr<Impl> pimpl;
	};

	struct item
	{
		item(int id=0, double wt=0.0);
		int page_id;   /*page id in page_db*/
		double weight;   /*use both freq and weight*/
	};

	struct raw_posting_list
	{
		raw_posting_list():idf(0.0){ }
		std::vector<item> posting_list; //vector of items, which has the same index
		double idf; // idf,seen IR theory
	};

	struct disk_index_header
	{
		char name[words_length_max];
		int size;
		int offset;
		double idf;
	};

	struct disk_index_data
	{
		int page_id;
		double weight;
	};

}
#endif
